package roaring

type shortIterable interface {
	hasNext() bool
	next() uint16
}

type shortPeekable interface {
	shortIterable
	peekNext() uint16
	advanceIfNeeded(minval uint16)
}

type shortIterator struct {
	slice []uint16
	loc   int
}

func ( *shortIterator) () bool {
	return .loc < len(.slice)
}

func ( *shortIterator) () uint16 {
	 := .slice[.loc]
	.loc++
	return 
}

func ( *shortIterator) () uint16 {
	return .slice[.loc]
}

func ( *shortIterator) ( uint16) {
	if .hasNext() && .peekNext() <  {
		.loc = advanceUntil(.slice, .loc, len(.slice), )
	}
}

type reverseIterator struct {
	slice []uint16
	loc   int
}

func ( *reverseIterator) () bool {
	return .loc >= 0
}

func ( *reverseIterator) () uint16 {
	 := .slice[.loc]
	.loc--
	return 
}

type arrayContainerUnsetIterator struct {
	content []uint16
	// pos is the index of the next set bit that is >= nextVal.
	// When nextVal reaches content[pos], pos is incremented.
	pos     int
	nextVal int
}

func ( *arrayContainerUnsetIterator) () uint16 {
	 := .nextVal
	.nextVal++
	for .pos < len(.content) && uint16(.nextVal) >= .content[.pos] {
		.nextVal++
		.pos++
	}
	return uint16()
}

func ( *arrayContainerUnsetIterator) () bool {
	return .nextVal < 65536
}

func ( *arrayContainerUnsetIterator) () uint16 {
	return uint16(.nextVal)
}

func ( *arrayContainerUnsetIterator) ( uint16) {
	if !.hasNext() || .peekNext() >=  {
		return
	}
	.nextVal = int()
	.pos = binarySearch(.content, )
	if .pos < 0 {
		.pos = -.pos - 1
	}
	for .pos < len(.content) && uint16(.nextVal) >= .content[.pos] {
		.nextVal++
		.pos++
	}
}

func newArrayContainerUnsetIterator( []uint16) *arrayContainerUnsetIterator {
	 := &arrayContainerUnsetIterator{content: , pos: 0, nextVal: 0}
	for .pos < len(.content) && uint16(.nextVal) >= .content[.pos] {
		.nextVal++
		.pos++
	}
	return 
}